//package com.whxd.system.user.rest;
//
//import java.net.URI;
//
//import javax.validation.Validator;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.ResponseStatus;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.util.UriComponentsBuilder;
//
//import com.whxd.framework.common.exception.RestException;
//import com.whxd.framework.common.validator.BeanValidators;
//import com.whxd.framework.common.web.MediaTypes;
//import com.whxd.system.user.entity.User;
//import com.whxd.system.user.service.UserService;
//
//@RestController
//@RequestMapping(value = "/api/v1/user")
//public class UserRestController {
//
//	private static Logger logger = LoggerFactory.getLogger(UserRestController.class);
//
//	@Autowired
//	private UserService userService;
//
//	@Autowired
//	private Validator validator;
//
//	@RequestMapping(method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
//	public Iterable<User> list() {
//		return userService.findAll();
//	}
//
//	@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
//	public User get(@PathVariable("id") Long id) {
//		User user = userService.findOne(id);
//		if (user == null) {
//			String message = "用户不存在(id:" + id + ")";
//			logger.warn(message);
//			throw new RestException(HttpStatus.NOT_FOUND, message);
//		}
//		return user;
//	}
//
//	@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
//	public ResponseEntity<?> register(@RequestBody User user, UriComponentsBuilder uriBuilder) {
//		// 调用JSR303 Bean Validator进行校验, 异常将由RestExceptionHandler统一处理.
//		BeanValidators.validateWithException(validator, user);
//
//		userService.save(user);
//
//		// 按照Restful风格约定，创建指向新任务的url, 也可以直接返回id或对象.
//		Long id = user.getId();
//		URI uri = uriBuilder.path("/api/v1/user/" + id).build().toUri();
//		HttpHeaders headers = new HttpHeaders();
//		headers.setLocation(uri);
//
//		return new ResponseEntity(headers, HttpStatus.CREATED);
//	}
//
//	@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaTypes.JSON)
//	@ResponseStatus(HttpStatus.NO_CONTENT)
//	// 按Restful风格约定，返回204状态码, 无内容. 也可以返回200状态码.
//	public void update(@RequestBody User user) {
//		// 调用JSR303 Bean Validator进行校验, 异常将由RestExceptionHandler统一处理.
//		BeanValidators.validateWithException(validator, user);
//
//		// 保存任务
//		userService.update(user);
//	}
//
//	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//	@ResponseStatus(HttpStatus.NO_CONTENT)
//	public void delete(@PathVariable("id") Long id) {
//		userService.delete(id);
//	}
//}
